<%@ tag pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<%@ tag import="java.lang.*" %>
<%@ tag import="org.apache.commons.beanutils.BeanUtils" %>	
<%@ tag import="com.pearlsoft.util.StringUtils" %>
<%@ tag import="com.pearlsoft.ui.core.PageContextUtils" %>

<%-- 通用属性  --%>
<%@ attribute rtexprvalue="true" required="false" name="var"%>
<%@ attribute rtexprvalue="true" required="false" name="id"%>
<%@ attribute rtexprvalue="true" required="false" name="config" 
	description="如果为true，只输出配置项，如果为false，输出内容如new cmpclass(config)，默认为false"%>
<%@ attribute rtexprvalue="true" required="false" name="disabled"%>
<%@ attribute rtexprvalue="true" required="false" name="hidden"%>
<%@ attribute rtexprvalue="true" required="false" name="renderTo"%>
<%@ attribute rtexprvalue="true" required="false" name="scripts"%>
<%@ attribute rtexprvalue="true" required="false" name="styles"%>
<%@ attribute rtexprvalue="true" required="false" name="width" %>
<%@ attribute rtexprvalue="true" required="false" name="height" %>

<%-- 扩展属性  --%>
<%@ attribute rtexprvalue="true" required="true" name="handlerName" description="handlerName的名称" %>
<%@ attribute rtexprvalue="true" required="false" name="handlerMethod"  description="handlerMethod的名称,默认为handler"%>
<%@ attribute rtexprvalue="true" required="fale" name="datasetName" description="datasetName的名称" %>
<%@ attribute rtexprvalue="true" required="false" name="conditions"  description="查询条件数组 可以为对象，或者数组;如:{fieldName:'id',value:'001'}或[{fieldName:'id',value:'001'}]"%>
<%@ attribute rtexprvalue="true" required="false" name="baseConditions"  description="基础查询条件数组 可以为对象，或者数组;如:{fieldName:'id',value:'001'}或[{fieldName:'id',value:'001'}]"%>


<%@ attribute rtexprvalue="true" required="false" name="fields" description="model的字段数组" %>
<%@ attribute rtexprvalue="true" required="false" name="model" description="store中的model" %>
<%@ attribute rtexprvalue="true" required="false" name="autoLoad" description="是否自动加载，默认为是" %>
<%@ attribute rtexprvalue="true" required="false" name="showPaging" description="是否显示分页，默认为是" %>
<%@ attribute rtexprvalue="true" required="false" name="pageSize"   description="每页的记录数,，默认为15;只有当showPaging=true是才有效" %>
<%@ attribute rtexprvalue="true" required="false" name="showCheckbox" description="是否显示Checkbox，默认为否" %>
<%@ attribute rtexprvalue="true" required="false" name="singleSelect" description="是否单选" %>
<%@ attribute rtexprvalue="true" required="false" name="title" %>
<%@ attribute rtexprvalue="true" required="false" name="editable" description="是否可编辑，默认为false"%>
<%@ attribute rtexprvalue="true" required="false" name="forceFit" description="Grid内部UI是否自动填充满,默认是"%>

<%
	init();
%>
<plst:cmpResources scripts="${scripts}" styles="${styles}" >

	<plsc:topScript>
		<plsc:component name="Pearlsen.PJsonStore" var="${storeID}_store">
			<plsc:attr name="autoLoad" type="boolean">${empty(autoLoad)?true:autoLoad}</plsc:attr>
			<plsc:attr name="fields" type="direct" test="${!empty(fields)}" >${fields}</plsc:attr>
			<plsc:attr name="model" type="string" test="${!empty(model)}" >${model}</plsc:attr>
			<plsc:attr name="handlerName" test="${!empty(handlerName)}" type="string">${handlerName}</plsc:attr>
			<plsc:attr name="handlerMethod" test="${!empty(handlerMethod)}" type="string">${handlerMethod}</plsc:attr>
			<plsc:attr name="datasetName" test="${!empty(datasetName)}" type="string">${datasetName}</plsc:attr>
			<plsc:attr name="conditions" test="${!empty(conditions)}" type="direct">${conditions}  </plsc:attr>
			<plsc:attr name="baseConditions" test="${!empty(baseConditions)}" type="direct">${baseConditions}  </plsc:attr>
			<c:if test="${empty(showPaging)?true:showPaging}">
				<plsc:attr name="pageSize" type="int" >${empty(pageSize) ? 15:pageSize }</plsc:attr>
			</c:if>
			<plsc:listeners>
				<plsc:handler name="beforeload" funcName="Pls.TAG.COMMON.storeBeforeload"></plsc:handler>
			</plsc:listeners>
		</plsc:component>
		<c:if test="${!empty(showCheckbox) && showCheckbox }">
			<plsc:component name="Ext.selection.CheckboxModel" var="${storeID}_model" >
				<c:choose>
					<c:when test="${!empty(singleSelect) && singleSelect }">
						<plsc:attr name="mode">SINGLE</plsc:attr>
					</c:when>
					<c:otherwise>
						<plsc:attr name="mode">MULTI</plsc:attr>
					</c:otherwise>
				</c:choose>
			</plsc:component>
		</c:if>
		<c:if test="${ empty(showPaging)?true:showPaging }">
			<plsc:component name="Ext.PagingToolbar" var="${storeID}_paging">
				<plsc:attr name="store" type="direct">${storeID}_store</plsc:attr>
				<plsc:attr name="displayInfo" type="boolean">true</plsc:attr>
				<plsc:attr name="displayMsg" type="string">当前 {0} - {1} 共 {2}</plsc:attr>
			</plsc:component>
		</c:if>
		<c:if test="${!empty(editable) && editable }">
			<plsc:component name="Ext.grid.plugin.CellEditing" var="${storeID}_cellEdit">
				<plsc:attr name="clicksToEdit" type="int">1</plsc:attr>
			</plsc:component>
		</c:if>
	</plsc:topScript>
	<plsc:component name="Ext.grid.Panel" var="${var}" config="${config}"  >
		<plsc:attr name="id" test="${!empty(id)}">${id}</plsc:attr>
		<plsc:attr name="xtype" test="${config == true}">gridpanel</plsc:attr>
		<plsc:attr name="disabled" test="${!empty(disabled)}" type="boolean" >${disabled}</plsc:attr>
		<plsc:attr name="hidden" test="${!empty(hidden)}" type="boolean" >${hidden}</plsc:attr>		
		<plsc:attr name="renderTo" test='<%=StringUtils.isNotEmpty(renderTo)%>'
			type='<%= StringUtils.getRenderType(renderTo)%>'>${renderTo}</plsc:attr>
		<plsc:attr name="width" test="${!empty(width)}"  type="int" >${width}</plsc:attr>
		<plsc:attr name="height" test="${!empty(height)}"  type="int" >${height}</plsc:attr>
		<plsc:attr name="title" test="${!empty(title)}"  type="string" >${title}</plsc:attr>
		<%-- UI特性  --%>
		<plsc:attr name="editable" type="boolean" >${empty(editable)?false:editable}</plsc:attr>
		<plsc:attr name="viewConfig">
			<plsc:value>
				<plsc:attr name="forceFit" type="boolean" >${empty(forceFit)?true:forceFit}</plsc:attr>
			</plsc:value>
		</plsc:attr>
		<%-- 扩展属性  --%>
		<plsc:attr name="store" type="direct">${storeID}_store</plsc:attr>
		<c:if test="${!empty(showCheckbox) && showCheckbox }">
			<plsc:attr name="selModel" type="direct">${storeID}_model</plsc:attr>
		</c:if>
		<c:if test="${ empty(showPaging)?true:showPaging }">
			<plsc:attr name="bbar" type="direct">${storeID}_paging</plsc:attr>
		</c:if>
		<c:if test="${!empty(editable) && editable }">
			<plsc:attr name="plugins" type="array">
				<plsc:value type="direct" >${storeID}_cellEdit</plsc:value>
			</plsc:attr>
		</c:if>
		
		
		<jsp:doBody/>
		</plsc:component>
</plst:cmpResources>

<%!
public void init (){
	this.getJspContext().setAttribute("storeID", 
			PageContextUtils.getCmpId(id, this.getJspContext()),PageContext.REQUEST_SCOPE);
}
%>

